#pragma once 


#include "rocksdb/comparator.h"
#include "Cast.h"

namespace helper {
namespace demo {

template<typename T>
class CastComparator : public ::rocksdb::Comparator {
public:
  using cast_type = T;

  explicit CastComparator(const Cast<cast_type> & cast) : cast_(cast) {}
  ~CastComparator(){}

  int Compare(const Slice & left, const Slice & right) const override{ //for Comparator
    return cast_.compare(left, right);
  }
  const char * Name() const override{
    return cast_.name().c_str();
  }
  void FindShortestSeparator(std::string* start, const ::rocksdb::Slice& limit) const override {}
  void FindShortSuccessor(std::string* key) const override {}

private:
  Cast<cast_type> cast_;
}; 


template<typename T>
::rocksdb::Comparator * newCastComparator(const Cast<T> & cast) {
  static ::rocksdb::Comparator * __comp = nullptr;
  if(__comp == nullptr){
    __comp = new CastComparator<T>(cast);
  }
  return __comp;
}

}//namespace demo
}//namespace helper
